import React from 'react';

import BaseModelNew from './BaseModelNew';
import Config from '../config';

export default class JifenMallModel extends BaseModelNew {
  constructor() {
    super();

    this.sendRequestPoint = this.sendRequestPoint.bind(this);
    this.sendRequestSign = this.sendRequestSign.bind(this);
    this.sendRequestItems = this.sendRequestItems.bind(this);
    this.sendRequestMyDuihuan = this.sendRequestMyDuihuan.bind(this);
    this.sendRequestAward = this.sendRequestAward.bind(this);
    this.sendToSign = this.sendToSign.bind(this);
    this.sendLuckerList = this.sendLuckerList.bind(this);
    this.sendChoujiang = this.sendChoujiang.bind(this);
    this.sendRequestItemData = this.sendRequestItemData.bind(this);
    this.sendBuyDuihuanItem = this.sendBuyDuihuanItem.bind(this);
    this.sendPointConfig = this.sendPointConfig.bind(this);
  }

  //http://118.89.111.124/dqapp/points/owned
  sendRequestPoint(data, callback){
    var url = Config.serverUrl + "/points/owned";
    this.sendGet(url, callback);
  }
  sendPointConfig(data, callback){
    var url = Config.serverUrl + "/admin/point/config";
    this.sendGet(url, callback);
  }
  sendRequestSign(data, callback){
    var url = Config.serverUrl + "/signs";
    this.sendGet(url, callback);
  }

  sendToSign(data, callback){
    var url = Config.serverUrl + "/signs";
    this.sendPost(url, JSON.stringify(data), callback);
  }

  sendRequestItems(data, callback){
    var url = Config.serverUrl + "/items?" + "page=" + data.page + "&page_size=" + data.page_size +
      "&sort_id=" + data.sort_id + "&tag=" + data.tag;
    this.sendGet(url, callback);
  }

  //http://118.89.111.124/dqapp/items/owned?page=1&page_size=5
  //我的兑换
  sendRequestMyDuihuan(data, callback) {
    var url = Config.serverUrl + "/items/owned?" + "page=" + data.page + "&page_size=" + data.page_size +
      "&sort_id=" + data.sort_id;
    this.sendGet(url, callback);
  }

  sendRequestAward(data, callback){
    var url = Config.serverUrl + "/awards";
    this.sendGet(url, callback);
  }

  sendLuckerList(data, callback){
    var url = Config.serverUrl + "/awards/winned?page=" + data.page + "&page_size=" + data.page_size;
    if(data.owned != undefined) {
      url += "&owned=" + data.owned;
    }
    this.sendGet(url, callback);
  }

  sendChoujiang(data, callback){
    var url = Config.serverUrl + "/awards";
    this.sendPost(url, JSON.stringify(data), callback);
  }

  sendRequestItemData(data, callback) {
    var url = Config.serverUrl + "/items/" + data.item_id;
    this.sendGet(url, callback);
  }

  sendBuyDuihuanItem(data, callback) {
    var url = Config.serverUrl + "/items/" + data.item_id + "?num=" + data.buy_num;
    this.sendPost(url, JSON.stringify(data), callback);
  }
}
